<?php declare(strict_types=1);

namespace app\middleware;
use app\exception\PermissionDeny;
use app\Request;
use app\facade\logic\Auth as FaAuthLogic;

class Auth {

    public function handle(Request $request, \Closure $next)
    {
        // 获取权限URL
        $path = $request->baseUrl();

        if(!$this->hasAuth($path)){
            throw new PermissionDeny();
        }

        return $next($request);
    }

    private function hasAuth($path){
        //
        $result = FaAuthLogic::checkAuth($path);
        return $result;
    }

}